package com.medusa.aps.business.modules.modeling.model.input;

import com.medusa.aps.business.model.constant.RegexPool;
import com.medusa.aps.business.modules.modeling.mp.entity.WorkingProcedure;
import com.medusa.aps.business.common.web.valid.group.Update;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * @author miskw
 * @date 2023/9/4
 */
@Data
@Validated
@Accessors(chain = true)
@Schema(description = "新增工序实体")
public class WorkingProcedureDTO {
    /**
     * 工序id
     */
    @Schema(description = "工序id")
    @NotNull(groups = Update.class, message = "工序id不能为空")
    private Integer id;
    /**
     * 工序编码
     */
    @Schema(description = "工序编码")
    @NotNull(message = "工序编码不能为空")
    @Size(max = 50, message = "工序编码不能超过50个字")
    @Pattern(regexp = RegexPool.ORDER_NO, message = "工序编码只支持数字、字母、符号")
    private String processCode;
    /**
     * 工序名称
     */
    @Schema(description = "工序名称")
    @NotNull(message = "工序名称不能为空")
    @Size(max = 50, message = "工序名称不能超过50个字")
    private String processName;
    /**
     * 备注
     */
    @Schema(description = "工序描述")
    @Size(max = 50, message = "工序描述不能超过50个字")
    private String remarks;
    /**
     * 工序设备实体
     */
    @Valid
    @Schema(description = "工序设备实体")
    @NotNull(message = "工序设备不能为空")
    @Size(min = 1, message = "工序设备最少添加一条")
    private List<WorkingProcedureEquipmentDTO> workingProcedureEquipments;

    public WorkingProcedure toWorkingProcedure() {
        return new WorkingProcedure()
                .setId(id)
                .setProcessCode(processCode)
                .setProcessName(processName)
                .setRemarks(remarks);
    }

}
